<template>
	<view>
		<view class="nav-box" :style="{'height':height+'px','background':bgColor}">
			<view class="status_bar" :style="{'height':statusBarHeight+'px'}"></view>
			<view class="nav-main flex items-center" :style="{height: navBarHeight+'px'}">
				<view class="search-input ml-30">
					<uni-icons type="search" size="16"></uni-icons>
					<input type="text" v-model="searchWords" placeholder="输入搜索内容" class="ml-20"
						style="font-size: 24rpx;" />
					<view class="font-24 mr-20" @click="search">搜索</view>
				</view>
			</view>
		</view>
		<view class="flex space-between flex-align-end p-30 bg-g" style="position: sticky;"
			:style="{top: (height + 69) + 'rpx'}">
			<view class="flex font-white">
				<view class="mr-40 text-center" @click="setIndex(0)">
					<view :class="[selectIndex === 0 ? 'list-select' : '']" style="width: 68rpx;">推荐</view>
					<view class="list-bord mt-10" v-if="selectIndex === 0"></view>
				</view>
				<view class="mr-40 text-center" @click="setIndex(1)">
					<view :class="[selectIndex === 1 ? 'list-select' : '']" style="width: 68rpx;">最新</view>
					<view class="list-bord mt-10" v-if="selectIndex === 1"></view>
				</view>
				<view class="mr-40 text-center" @click="setIndex(2)">
					<view :class="[selectIndex === 2 ? 'list-select' : '']" style="width: 68rpx;">附近</view>
					<view class="list-bord mt-10" v-if="selectIndex === 2"></view>
				</view>
			</view>
			<view class="flex items-center">
				<view class="font-20 pt-5 pb-5 pl-20 pr-20 bg-white border-radius2 flex">
					<picker @change="bindPickerChange" :value="index" :range="array">
						<view class="uni-input">{{array[index]}}</view>
					</picker>
					<uni-icons custom-prefix="iconfont" class="ml-10" type="icon-youxia" size="5"
						color="#000"></uni-icons>
				</view>
				<view class="font-20 pt-5 pb-5 pl-20 pr-20 bg-white ml-10 border-radius2" @click="showFilter = !showFilter">筛选<uni-icons
						custom-prefix="iconfont" class="ml-10" type="icon-youxia" size="5" color="#000"></uni-icons>
				</view>
			</view>
		</view>
		<view class="text-center mt-200" v-if="type === 1 && resumeLists.length === 0">暂无信息...</view>
		<view class="text-center mt-200" v-if="type === 0 && inviteList.length === 0">暂无信息...</view>
		<view v-if="type === 0" class="pl-30 pr-30 pt-30" v-for="(item, index) in inviteList" :key="index"
			@click="$goRoute.goUrl('/pages/lists/details?id='+item.id)">
			<view class="bg-white pl-20 pr-20 pt-30 pb-30 border-radius">
				<view class="flex space-between flex-align-end">
					<view class="font-bold font-30">{{item.name}}</view>
					<view class="font-26 font-g font-bold">{{item.payLow}}-{{item.payHigh}}</view>
				</view>
				<view class="flex font-26 mt-20">
					<view>{{item.companyId_dictText}}</view>
					<!-- <view class="ml-40">2000-5000人</view> -->
				</view>
				<view class="flex font-22 mt-10" style="color: #686E6E;">
					<view class="pt-10 pb-10 pl-30 pr-30">{{item.jobNature}}</view>
					<view class="pt-10 pb-10 pl-30 pr-30">{{item.peopleNum}}人</view>
					<view class="pt-10 pb-10 pl-30 pr-30">{{item.education_dictText}}</view>
					<view class="pt-10 pb-10 pl-30 pr-30">{{item.experience}}</view>
				</view>
				<view class="flex space-between items-center mt-10">
					<view class="flex items-center">
						<image src="../../static/images/avatar.png" mode=""
							style="width: 50rpx;height: 50rpx;border-radius: 50%;"></image>
						<view class="font-24 ml-10">{{item.hruserId_dictText}}</view>
					</view>
					<view class="font-24">{{item.city}}</view>
				</view>
			</view>
		</view>

		<view class="pl-30 pr-30 pt-30" v-for="(item, index) in resumeLists" :key="index" v-if="type === 1"
			@click="$goRoute.goUrl('/pages/lists/info?id='+item.id)">
			<view class="bg-white pl-30 pr-30 pt-20 pb-20 border-radius">
				<view class="flex space-between items-center mt-10">
					<view class="flex items-center" @click="$goRoute.goUrl('/pages/lists/info?id='+item.id)">
						<image src="../../static/images/avatar.png" mode=""
							style="width: 70rpx;height: 70rpx;border-radius: 50%;"></image>
						<view class=" ml-20">
							<view class="font-28">{{item.username}}</view>
							<view class="font-22 mt-10 font-grey">{{calculateAge(item.birthday)}}岁 |
								{{calculateAge(item.workTime)}}年
							</view>
						</view>
					</view>
					<view class="font-24 font-g border-g border-radius pt-10 pb-10 pl-20 pr-20">打招呼</view>
				</view>
				<view class="flex items-center mt-20" @click="$goRoute.goUrl('/pages/lists/info?id='+item.id)">
					<uni-icons custom-prefix="iconfont" type="icon-aixin_shixin" size="16" color="#46B4B1"></uni-icons>
					<view class="font-24 ml-20">期望：<text v-for="(itd, idx) in item.zbApplyintentionList"
							:key="idx">{{itd.expectPosition}}</text></view>
				</view>
				<view class="flex items-center mt-20" @click="$goRoute.goUrl('/pages/lists/info?id='+item.id)">
					<uni-icons custom-prefix="iconfont" type="icon-gongzuoxinxi" size="16" color="#46B4B1"></uni-icons>
					<view class="font-24 ml-20">{{item.zbApplyworkList[0].companyName}} ·
						{{item.zbApplyworkList[0].position}}</view>
				</view>
			</view>
		</view>
		
		<view class="filter" :style="{top: (height + 69) + 'rpx'}" v-if="showFilter">
			<view class="p-20 mt-40">
				<view class="p-20 bg-white border-radius">
					<view class="mb-20">
						<view class="font-26">学历</view>
						<view class="mt-20">
							<uni-data-select
							      v-model="filters.education"
							      :localdata="education_enum"
							      @change="change"
							    ></uni-data-select>
						</view>
					</view>
					<view class="mb-20">
						<view class="font-26">经验</view>
						<view class="mt-20">
							<uni-data-select
							      v-model="filters.experience"
							      :localdata="experience_enum"
							      @change="change"
							    ></uni-data-select>
						</view>
					</view>
					
					<view class="mb-20">
						<view class="font-26">职业类别</view>
						<view class="mt-20">
							<uni-data-select
							      v-model="filters.postion"
							      :localdata="range"
							      @change="change"
							    ></uni-data-select>
						</view>
					</view>
					
					<view class="mb-20">
						<view class="font-26">最低薪资</view>
						<view class="mt-20">
							<uni-easyinput v-model="form.pay_low" placeholder="请输入最低薪资" />
						</view>
					</view>
					<view class="mb-20">
						<view class="font-26">最高薪资</view>
						<view class="mt-20">
							<uni-easyinput v-model="form.pay_high" placeholder="请输入最高薪资" />
						</view>
					</view>
				</view>
			</view>
			<view class="filter-bottom">
				<view class="filter-btn" @click="reset">重置</view>
				<view class="filter-btn click-btn" @click="search">确定</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		list
	} from '../../api/invite';
	import {
		list as resumeList
	} from '../../api/apply_user.js'
	export default {
		data() {
			return {
				showFilter: false,
				height: 0,
				statusBarHeight: 0,
				navBarHeight: 0,
				searchWords: '',
				selectIndex: 0,
				array: ['东营市', '东营区', '河口区', '利津县', '广饶县'],
				index: 0,
				user: null,
				type: 0,
				pageNo: 1,
				pageSize: 10,
				resumeLists: [],
				inviteList: [],
				filters: {

				},
				education_enum: [
					{
						text: '初中及以下',
						value: '初中及以下'
					},{
						text: '中专/中技',
						value: '中专/中技'
					},{
						text: '高中',
						value: '高中'
					},{
						text: '大专',
						value: '大专'
					},{
						text: '本科',
						value: '本科'
					},{
						text: '硕士',
						value: '硕士'
					},{
						text: '博士',
						value: '博士'
					}
				],
				experience_enum: [
					{
						text: '实习',
						value: '实习'
					},{
						text: '1年以内',
						value: '1年以内'
					},{
						text: '1-3年',
						value: '1-3年'
					},{
						text: '3-5年',
						value: '3-5年'
					},{
						text: '5年以上',
						value: '5年以上'
					}
				],
			};
		},
		onLoad() {
			this.getHeight()
		},
		onShow() {
			this.getUserType()
		},
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: '河口人才招聘小程序',
				path: '/pages/lists/lists'
			}
		},
		onReachBottom() {
			if (this.user.type === 0) {
				this.getInviteList()
			} else {
				this.getResumeList()
			}
		},
		methods: {
			reset() {
				this.filters = {}
				this.search()
			},
			getResumeList() {
				uni.showLoading({
					title: '加载中'
				})
				resumeList({
					pageSize: this.pageSize,
					pageNo: this.pageNo,
					username: this.searchWords,
					home_city: this.array[this.index],
					...this.filters
				}).then(res => {
					if (this.pageNo === 1) {
						this.resumeLists = res.result.records
					} else {
						this.resumeLists.push(...res.result.records)
					}
					this.pageNo += 1
					uni.hideLoading()
				})
			},
			getInviteList() {
				uni.showLoading({
					title: '加载中'
				})
				list({
					pageSize: this.pageSize,
					pageNo: this.pageNo,
					name: this.searchWords,
					city: this.array[this.index],
					...this.filters
				}).then(res => {
					if (this.pageNo === 1) {
						this.inviteList = res.result.records
					} else {
						this.inviteList.push(...res.result.records)
					}
					this.pageNo += 1
					uni.hideLoading()
				})
			},
			getUserType() {
				const user = uni.getStorageSync('userInfo')
				if (user) {
					this.user = user
					this.type = user.type
					if (user.type === 1) {
						uni.setTabBarItem({
							index: 1,
							text: '人才',
							iconPath: 'static/images/t-2.png',
							selectedIconPath: 'static/images/t-2-s.png'
						})
						this.getResumeList()
					} else {
						this.getInviteList()
					}
				} else {
					this.getInviteList()
				}
			},
			bindPickerChange: function(e) {
				this.index = e.detail.value
				this.search()
			},
			search() {
				this.pageNo = 1
				this.showFilter = false
				uni.showLoading({
					title: '加载中...'
				})
				if (this.type === 0) {
					this.getInviteList()
				} else {
					this.getResumeList()
				}
				setTimeout(() => {
					uni.hideLoading()
				}, 1000)
			},
			setIndex(index) {
				this.selectIndex = index
				this.search()
			},
			//获取屏幕导航栏高度
			getHeight() {
				if (wx.canIUse('getMenuButtonBoundingClientRect')) {
					let sysInfo = wx.getSystemInfoSync(); //状态栏的高度
					this.statusBarHeight = sysInfo.statusBarHeight;
					// 胶囊位置信息
					let rect = wx.getMenuButtonBoundingClientRect();
					this.menuButtonRect = JSON.parse(JSON.stringify(rect));
					// 导航栏高度
					let navBarHeight = (rect.top - sysInfo.statusBarHeight) * 2 + rect.height;
					this.navBarHeight = navBarHeight;
					// 自定义导航栏的高度
					this.height = sysInfo.statusBarHeight + navBarHeight;
				} else {
					wx.showToast({
						title: '您的微信版本过低，界面可能会显示不正常',
						icon: 'none',
						duration: 4000
					});
				}
			},
			calculateAge(birthdate) {
				var today = new Date();
				var birthDate = new Date(birthdate);
				var age = today.getFullYear() - birthDate.getFullYear();
				var monthDiff = today.getMonth() - birthDate.getMonth();

				if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
					age--;
				}

				return age;
			},
		}
	}
</script>

<style lang="less">
	page {
		background-color: #F6F6F6;
	}

	.nav-box {
		background-color: #46b4b1;
		position: sticky;
		top: 0;
		z-index: 9999;

		.search-input {
			background-color: rgba(255, 255, 255, .8);
			height: 30px;
			display: flex;
			align-items: center;
			border-radius: 50rpx;
			padding: 0 30rpx;
		}
	}

	.list-bord {
		background: #fff;
		width: 68rpx;
		height: 8rpx;
	}
	
	.filter {
		position: fixed;
		width: 100vw;
		height: 70vh;
		background-color: #46b4b1;
		z-index: 999;
		
		.filter-bottom {
			position: absolute;
			width: 100%;
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: space-around;
			
			.filter-btn {
				width: 45vw;
				text-align: center;
				padding: 10rpx 0;
				background-color: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
			}
			
			.click-btn {
				color: #46b4b1;
			}
		}
	}
</style>